//
//  PromotionTopV.m
//  TT
//
//  Created by Lenny on 16/4/19.
//  Copyright © 2016年 Lenny. All rights reserved.
//

#import "PromotionTopV.h"

@interface PromotionTopV ()

@property(nonatomic,strong)UIButton *btn1;
@property(nonatomic,strong)UIButton *btn2;
@property(nonatomic,copy)void(^block)(UIButton *btn);

@end

@implementation PromotionTopV

#pragma mark - public motheds

- (void)addUI {
    
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.btn1];
    [self addSubview:self.btn2];
    
    UIView *midLineV = [[UIView alloc] init];
    midLineV.backgroundColor = WL_line_Color;
    [self addSubview:midLineV];
    
    UIView *downLineV = [[UIView alloc] init];
    downLineV.backgroundColor = WL_line_Color;
    [self addSubview:downLineV];
    
    __weak typeof(self) weakSelf = self;
    [self.btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.width.mas_equalTo(k_screen_w / 2);
    }];
    
    [self.btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.width.equalTo(weakSelf.btn1);
    }];
    
    [midLineV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.equalTo(weakSelf);
        make.top.mas_equalTo(5);
        make.bottom.mas_equalTo(-5);
        make.width.mas_equalTo(1);
    }];
    
    [downLineV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
}

- (void)addEvent:(void (^)(UIButton *))eventBlock {
    
    self.block = eventBlock;
}

#pragma mark - event motheds

- (void)btnAction:(UIButton *)sender {
    
    if (self.block) self.block(sender);
}

#pragma mark - setters and getters

- (UIButton *)btn1 {
    
    if (_btn1 == nil) {
        
        _btn1 = [[UIButton alloc] init];
        _btn1.tag = 1;
        [_btn1 setImage:[UIImage imageNamed:@"icon_time"] forState:UIControlStateNormal];
        [_btn1 setTitle:@"全部优惠券" forState:UIControlStateNormal];
        [_btn1 setTitleColor:WL_Desc_Color forState:UIControlStateNormal];
        [_btn1 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn1;
}

- (UIButton *)btn2 {
    
    if (_btn2 == nil) {
        
        _btn2 = [[UIButton alloc] init];
        _btn2.tag = 2;
        [_btn2 setImage:[UIImage imageNamed:@"icon_time"] forState:UIControlStateNormal];
        [_btn2 setTitle:@"我的优惠券" forState:UIControlStateNormal];
        [_btn2 setTitleColor:WL_Desc_Color forState:UIControlStateNormal];
        [_btn2 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn2;
}

@end
